package com.example.admin;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.widget.EditText;

import com.example.admin.SQLite.admin;
import com.example.admin.SQLite.dao.AdminDao;
import com.example.admin.base.BaseActivity;

import java.util.List;

public class AdminLoginActivity extends BaseActivity {
EditText tvName,tvPass;
AdminDao adminDao;
    @Override
    public void setContentView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_admin_login);
        adminDao=new AdminDao(this);
        tvName=findViewById(R.id.tvName);
        tvPass=findViewById(R.id.tvPass);
        findViewById(R.id.tv_login).setOnClickListener(v -> {
            String name=tvName.getText().toString().trim();
            String pass=tvPass.getText().toString().trim();

            if (!TextUtils.equals("admin",name)){
                toast("账号错误");
                return;
            }
            List<admin> list=adminDao.getUserList();
            Log.e(TAG, "setContentView: "+list.toString() );
            if (list.size()==0){
                if (!TextUtils.equals("admin",pass)){
                    toast("密码错误");
                    return;
                }else {
                    admin bea=new admin();
                    bea.adminName="admin";
                    bea.adminPassword="admin";
                    adminDao.addUserData(bea);
                    startActivity(new Intent(this, AdminActivity.class));
                }
            }else {
                if (!TextUtils.equals(list.get(0).adminPassword,pass)){
                    toast("密码错误");
                    return;
                }
                startActivity(new Intent(this, AdminActivity.class));
            }
        });

    }

    @Override
    public void setInitView() {

    }
}